from DataRecorder import Recorder
from DrissionPage import WebPage

def main():



    page = WebPage()

    recorder = Recorder('data.xlsx')


    count = 1
    while count <= 10:

        url = "https://www.zhipin.com/web/geek/job?city=100010000&position=100101"
        # 访问地址
        page.get(url)

        count += 1

        # 等待页面加载,（s模式无法进行此操作）
        page.wait.load_start()

        try:
            # 点击×按钮
            page("/html/body/div[9]/div[2]/div[1]/span/i").click()
        except:
            pass

        # 切换到收发数据包模式,会重新访问网站
        # page.change_mode()

        boxs = page(".job-list-box").eles(".job-card-wrapper")

        for item in boxs:
            # 公司名称
            comName = item(".company-name").text
            # 岗位名称
            jobName = item(".job-name").text
            # 地址
            jobArea = item(".job-area").text
            # 薪资
            salary = item(".salary").text
            # 经验和学历
            temp = item(".job-info clearfix").eles("tag:li")
            exp = temp[0].text
            edu = temp[1].text
            # 公司类型、状态、规模
            comTag = ""
            for li in item(".company-tag-list").eles("tag:li"):
                comTag += li.text+","
            # 岗位需求
            comNeed = ""
            for li in item(".job-card-footer clearfix").eles("tag:li"):
                comNeed += li.text+","
            # 公司福利
            welfare = item(".info-desc").text

            recorder.add_data((jobName, jobArea, salary, exp, edu, comName, comTag, comNeed, welfare))

            page(".options-pages").ele('text:{}'.format(count)).click()



if __name__ == '__main__':
    main()